<?php

namespace App\Http\Controllers;

use App\Person;
use Illuminate\Http\Request;

class PersonController extends Controller
{
    public function create(Request $request)
    {
        Person::create(
            $request->all()
        );
        
        return response()->json(
            [
                'success' => true
            ],
            201
        );
    }
    
    public function show(Person $person)
    {
        return $person->toJson();
    }
    /**
     * route person/{person}
     *
     * @param Request $request
     * @param Person $person
     * @return \Illuminate\Http\JsonResponse
     */
    public function update(Request $request, Person $person)
    {
        $request->validate(
            [
                'name' => 'required|string:min:3',
                'age' => 'required|int',
            ]
        );
        // update person
        $person->update($request->all());
        return response()->json(
            [
                'success' => true
            ],
            201
        );
    }
    
    public function delete(Person $person)
    {
        $person->delete();
        return response()->json(
            [
                'success' => true
            ],
            201
        );
    }
    
    
}
